package com.kabuda.zhugehot200_review;

/**
 * @author kabuda
 * @date 2025-03-27 22:30
 * @description
 */
public class x的平方根 {
    public static void main(String[] args) {
        System.out.println(mySqrt(10));
    }


    static int mySqrt(int x) {
        int left = 0;
        int right = x;
        int result = 0;
        while (left <= right) {
            int mid = left + (right - left) / 2;
            if ((long) mid * mid <= x) {
                result = mid;
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }
        return result;
    }
}
